<?php
session_start();

require_once("../database.include.php");

	$username=$_GET["username"];
	$groupname=$_GET["groupname"];

	$conn->beginTransaction();
	try {
			
		$stmt = $conn->prepare('INSERT INTO `group_user` (group_name, user_name) VALUES(?, ?)');
		$insertGroupUserSuccess = $stmt->execute( array( $groupname, $username ) );
		$conn->commit();
		echo "<br/>Success on inserting into group: " . $groupname . ", " . $username;
		return "<br/>Success on inserting into group: " . $groupname . ", " . $username;
	}	
	catch(PDOException $err) {
		$conn->rollBack();
		echo "<br/>Failure adding to group: " . $groupname . ", " . $username . ". Duplicate group & user combo.";		
		return "<br/>Failure adding to group: " . $groupname . ", " . $username . ". Duplicate group & user combo.";
	}
	catch(Exception $err) 
	{
		$conn->rollBack();
		echo "<br/>Internal failure adding to group: " . $groupname . ", " . $username . ".";
		return "Internal failure adding to group: " . $groupname . ", " . $username . ".";
	}
?>
